//获取应用实例
const app = getApp();
const adminService = require('../../service/beAdmin.services.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {
    },
    user: {},
    isLogin: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.userLogin();
    //隐藏分享
    wx.hideShareMenu();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  //分享
  onShareAppMessage: function (res) {
  },

  /**
   * 获取用户信息
   */
  getUserInfo: function (e) {
    var that = this;
    app.globalData.userInfo = e.detail.userInfo;
    this.setData({
      userInfo: e.detail.userInfo
    });
    //初始化登陆检查
    wx.showLoading({
      title: ''
    });

    app.wxInit({
      app: app, url: "/pages/mine/mine", reload: function () {
        var login1 = false;
        var login2 = false;
        if (app.globalData.user && app.globalData.user != '' && app.globalData.user != null) {
          console.log(app.globalData.user);
          login1 = true;
          that.setData({
            user: app.globalData.user
          })
        }
        if (app.globalData.userInfo && app.globalData.userInfo != '' && app.globalData.userInfo != null) {
          console.log(app.globalData.userInfo);
          login2 = true;
          that.setData({
            userInfo: app.globalData.userInfo
          })
        }

        if (login1 && login2) {
          that.setData({
            isLogin: true
          })
        }
      }
    });
  },
  getPhoneNumber: function (e) {
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
    console.log(e.currentTarget.dataset.id);
    var openId = e.currentTarget.dataset.id;
    var iv = e.detail.iv;
    var encryptedData = e.detail.encryptedData;
    adminService.canUpload({ app: app, openId: openId, iv: iv, encryptedData: encryptedData, success: function(res) {
      if(!res) {console.log("申请失败");}
    }});
  } 
})